package com.yxr.affairs.widget;


import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.View;

import com.yxr.affairs.utils.Utils;

public class WeekDayView extends View {

    private int mLineColor = Color.parseColor("#eeeeee");

    private int mWeeColor = Color.parseColor("#333333");

    private int mStrokeWidth = 2;
    private int mWeekSize = 14;

    private Paint paint;
    private DisplayMetrics mDisplayMetrics;

    private String[] weekString = new String[]{"日", "一", "二", "三", "四", "五", "六"};

    public WeekDayView(Context context, AttributeSet attrs) {
        super(context, attrs);

        mDisplayMetrics = getResources().getDisplayMetrics();
        paint = new Paint();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

//		int widthSize = MeasureSpec.getSize(widthMeasureSpec);
//		int widthMode = MeasureSpec.getMode(widthMeasureSpec);
//
//		int heightSize = MeasureSpec.getSize(heightMeasureSpec);
//		int heightMode = MeasureSpec.getMode(heightMeasureSpec);
//
//		if(heightMode == MeasureSpec.AT_MOST){
//			heightSize = mDisplayMetrics.densityDpi * 30;
//		}
//
//		if(widthMode == MeasureSpec.AT_MOST){
//			widthSize = mDisplayMetrics.densityDpi * 300;
//		}
//
//		setMeasuredDimension(widthSize, heightSize);

        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    @Override
    protected void onDraw(Canvas canvas) {

        int width = getWidth();
        int height = getHeight();

        paint.setAntiAlias(true);
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(mLineColor);
        paint.setStrokeWidth(mStrokeWidth);
        canvas.drawLine(0, 0, width, 0, paint);
        canvas.drawLine(0, height, width, height, paint);

        paint.setStyle(Paint.Style.FILL);
//		paint.setTextSize(mWeekSize * mDisplayMetrics.scaledDensity);
        paint.setTextSize(Utils.dp2px(getResources(), mWeekSize));
        int columnWidth = width / 7;

        for(int i=0; i < weekString.length; i++){
            String text = weekString[i];
            int fontWidth = (int) paint.measureText(text);
            int startX = columnWidth * i + (columnWidth - fontWidth)/2;
            int startY = (int) (height/2 - (paint.ascent() + paint.descent())/2);
            paint.setColor(mWeeColor);
            canvas.drawText(text, startX, startY, paint);
        }
    }

}